package org.dey.controller;


import org.dey.entity.Result;
import org.dey.pojo.Member;
import org.dey.pojo.PageVo;
import org.dey.pojo.User;
import org.dey.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author deyran
 * @classname
 * @see MemberController
 */
@RestController
public class MemberController {

    @Autowired(required = false)
    MemberService memberService;

    //    打开用户管理页面显示数据 @RequestParam /{pageno}/{pagesize} @PathVariable  @PathVariable
    //@RequestParam(value = "pagecurrent",defaultValue = "1")   @RequestParam(value = "pagesize",defaultValue = "5")
    @PostMapping("member.action/{pageNum}/{pagesize}")
    public PageVo<Member> memberlist(@RequestBody Member member,@PathVariable int pageNum,@PathVariable int pagesize){
        System.out.println("pagecurrent——pagesize"+pageNum+"——"+pagesize);
        PageVo<Member> members = memberService.querymember(member, pageNum, pagesize);
        return members;
    }

    //添加
    @PostMapping("member.action")
    public Result addmember(@RequestBody Member member){

        Result insertmember = memberService.insertmember(member);

        return insertmember;
    }

    //删除
    @DeleteMapping("member.action/{id}")
    public Result delmemberbyid(@PathVariable int id){

        Result delmember = memberService.delmember(id);

        return delmember;
    }

    //修改先根据id查到该数据
    @GetMapping("member.action/{id}")
    public Member querymemberbyid(@PathVariable Integer id){

        Member querymemberbyid = memberService.querymemberbyid(id);
        System.out.println("Controller——querymemberbyid——"+querymemberbyid);
        return querymemberbyid;
    }

    //根据id修改
    @PutMapping("member.action")
    public Result updatememberbyid(@RequestBody Member member){

        Result updatememberbyid = memberService.updatememberbyid(member);

        return updatememberbyid;
    }

    @GetMapping("queryuserrole.action")
    public List<User> getUserRole(){
        List<User> userRole = memberService.getUserRole();
        return userRole;
    }

    //根据档案号查
    @GetMapping("/findMemeberById.do/{id}")
    public Member queryRaByRaId(@PathVariable int id){
        return memberService.queryRaByRaId(id);
    }

}


